#include "calculator.pb.h"
#include "fastrpc/rpc.hpp"
using namespace fastrpc::log;
using namespace fastrpc::io;
using namespace fastrpc::net;
using namespace fastrpc::async;
using namespace fastrpc;
using namespace fastrpc::rpc;

auto client() -> Task<void> {
    auto res = co_await RpcClient::GetInstance("192.168.50.100", 10000);
    if (!res) {
        console.error("{}", res.error().message());
        co_return;
    }
    auto              client = std::move(res.value());
    CalculatorRequest request;
    request.set_m(10);
    request.set_n(2);
    auto result1 = co_await client.call<CalculatorRequest, CalculatorResponse>("123",
                                                                               "Calculator.Add",
                                                                               std::ref(request));
    std::cout << "response : " << result1.result() << std::endl;
    auto result2
        = co_await client.call<CalculatorRequest, CalculatorResponse>("1234",
                                                                      "Calculator.Subtract",
                                                                      std::ref(request));
    std::cout << "response : " << result2.result() << std::endl;
    auto result3
        = co_await client.call<CalculatorRequest, CalculatorResponse>("12345",
                                                                      "Calculator.Multiply",
                                                                      std::ref(request));
    std::cout << "response : " << result3.result() << std::endl;
    auto result4 = co_await client.call<CalculatorRequest, CalculatorResponse>("123456",
                                                                               "Calculator.Divide",
                                                                               std::ref(request));
    std::cout << "response : " << result4.result() << std::endl;
}

int main(int argc, char *argv[]) {
    SET_LOG_LEVEL(log::LogLevel::Info);
    runtime::CurrentThreadBuilder::default_create().block_on(client());
    return 0;
}
